package com.longdaji.decoration.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.longdaji.decoration.R;
import com.longdaji.decoration.bean.Comment;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Kanade on 2018/2/27 0027.
 */

public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.CommentHolder> {
    private List<Comment> mCommentList;
    private Context mContext;

    public CommentAdapter(List<Comment> commentList) {
        this.mCommentList = commentList;
    }

    @Override
    public CommentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_comment, parent, false);
        CommentHolder holder = new CommentHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(CommentHolder holder, int position) {
        Comment comment = mCommentList.get(position);
        Glide.with(mContext).load(comment.getUserPortraituUri()).into(holder.ivUserPortrait);
        holder.tvUserName.setText(comment.getUserName());
        holder.tvTime.setText(comment.getCommentTime());
        holder.tvCommentContent.setText(comment.getCommentContent());
        holder.tvCommentReplay.setText(Integer.valueOf(comment.getReplayCount()));
        holder.tvCommentSupport.setText(Integer.valueOf(comment.getSupportCount()));
    }

    @Override
    public int getItemCount() {
        return mCommentList.size();
    }

     class CommentHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_user_portrait)
        ImageView ivUserPortrait;
        @BindView(R.id.tv_user_name)
        TextView tvUserName;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_comment_content)
        TextView tvCommentContent;
        @BindView(R.id.tv_comment_replay)
        TextView tvCommentReplay;
        @BindView(R.id.tv_comment_support)
        TextView tvCommentSupport;

        public CommentHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
        // TODO: 2018/3/5 0005 onViewClicked

    }
}
